#include<iostream>
using namespace std;
#define SPACE 0
#define WALL 1
#define BIG 99999
int dx[] = { 0,0,1,-1};
int dy[] = {-1,1,0,0};
struct node{
	int state;
	bool available;
};

void constrain(node **table,int size,int x,int y){
	table[x][y].available = false;
	for(int direction =0;direction<4;direction++){
		for(int i=x,j=y;  ; ){
			i += dx[direction];
			j += dy[direction];
			if( (i>=size || i<0 || j>=size ||j<0))break;
			if(table[i][j].state == WALL)break;
			if( table[i][j].state == SPACE && table[i][j].available == true ){
				table[i][j].available = false;
			}
		}
	}
}
int getHeuristic(node **table,int size,int x,int y){
	
	if(table[x][y].state==WALL)return BIG;
	int heuristic = 0;
	for(int direction =0;direction<4;direction++){
		for(int i=x,j=y;  ; ){
			i += dx[direction];
			j += dy[direction];
			if( (i>=size || i<0 || j>=size ||j<0))break;
			if(table[i][j].state == WALL)break;
			if( table[i][j].state == SPACE && table[i][j].available == true ){
				heuristic ++;
			}
			
		}
	}
	return heuristic;
}
int search(node **table,int size){
	int count = 0;
	while(true){
		int minHeuristic = BIG;
		int stepx =-1;int stepy = -1;
		for(int i=0;i<size;i++){
			for(int j=0;j<size;j++){
				if(table[i][j].available == true){
					int temp = getHeuristic(table,size,i,j);
					if(temp<minHeuristic){
						minHeuristic = temp;
						stepx = i;
						stepy = j;
					}
				}
			}
		}
		if(stepx!=-1&&stepy!=-1){
			constrain(table,size,stepx,stepy);
		//	cout<<stepx<<" "<<stepy<<endl;
			count++;
		}else{
			return count;
		}
	}
}


int main(){
	int n;
	while(true){
		cin>>n;
		if(n ==0)break;
		else{
			node **table = new node*[n];
			for(int i=0;i<n;i++){
				table[i] = new node[n];
			}

			char temp;
			for(int y=0;y<n;y++){
					for(int x=0;x<n;x++){
						cin>>temp;
						if(temp == '.'){
							table[x][y].state = SPACE;
							table[x][y].available = true;
						}else if(temp == 'X'){
							table[x][y].state = WALL;
							table[x][y].available = false;
						}
					}
			}

			int result = search(table,n);
			cout<<result<<endl;
		}
	}
 
	return 0;
}